package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.activity.shuihu.ShuiHuBox;
import com.yanqu.road.entity.activity.shuihu.ShuiHuBoxItem;
import com.yanqu.road.entity.activity.shuihu.ShuiHuNotice;
import com.yanqu.road.pb.activity.ShuiHuActivityProto;

import java.util.ArrayList;
import java.util.List;

public class ShuiHuPb {

    public static ShuiHuActivityProto.ShuiHuBoxMsg.Builder parseShuiHuBoxMsg(ShuiHuBox shuiHuBox, long userId, long serverId) {
        ShuiHuActivityProto.ShuiHuBoxMsg.Builder builder = ShuiHuActivityProto.ShuiHuBoxMsg.newBuilder();
        builder.setRoundNo(shuiHuBox.getRoundNo());
        for (ShuiHuBoxItem boxItem : shuiHuBox.getBoxItemMap().values()) {
            // 只发已开启的
            if (boxItem.getUserBaseInfo().getUserAliasId() > 0) {
                builder.addItemList(parseShuiHuBoxItemMsg(boxItem));
                // 自己抽的卡标记一下
                if (boxItem.getUserId() == userId && boxItem.getUserBaseInfo().getServerId() == serverId) {
                    builder.addMyItemNo(boxItem.getItemNo());
                }
            }
        }
        return builder;
    }

    public static ShuiHuActivityProto.ShuiHuBoxItemMsg.Builder parseShuiHuBoxItemMsg(ShuiHuBoxItem boxItem) {
        ShuiHuActivityProto.ShuiHuBoxItemMsg.Builder builder = ShuiHuActivityProto.ShuiHuBoxItemMsg.newBuilder();
        builder.setItemNo(boxItem.getItemNo());
        builder.setCardId(boxItem.getCardId());
        return builder;
    }

    public static List<ShuiHuActivityProto.ShuiHuNoticeMsg> parseShuiHuNoticeMsgList(List<ShuiHuNotice> noticeList, int count) {
        int size = noticeList.size();
        int startIndex = size >= count ? size - count : 0;
        List<ShuiHuActivityProto.ShuiHuNoticeMsg> list = new ArrayList<>();
        for (; startIndex < size; startIndex++) {
            list.add(parseShuiHuNoticeMsg(noticeList.get(startIndex)).build());
        }
        return list;
    }

    public static ShuiHuActivityProto.ShuiHuNoticeMsg.Builder parseShuiHuNoticeMsg(ShuiHuNotice notice) {
        ShuiHuActivityProto.ShuiHuNoticeMsg.Builder builder = ShuiHuActivityProto.ShuiHuNoticeMsg.newBuilder();
        builder.setRoundNo(notice.getRoundNo());
        builder.setCardId(notice.getCardId());
        builder.setNickName(notice.getUserBaseInfo().getNickName());
        builder.setTime(notice.getCreateTime());
        return builder;
    }

    public static ShuiHuActivityProto.DrawCardDataMsg.Builder parseDrawCardDataMsg(ShuiHuBox box, ShuiHuBoxItem item) {
        ShuiHuActivityProto.DrawCardDataMsg.Builder builder = ShuiHuActivityProto.DrawCardDataMsg.newBuilder();
        builder.setRoundNo(box.getRoundNo());
        builder.setItemMsg(parseShuiHuBoxItemMsg(item));
        return builder;
    }

}
